/*********************************************************************
 *                                                                   *
 *  Js Css Minifier ( JsCssMin )                                     *
 *  Author: Igor Kanshyn                                             *
 *  Copyright (c) 2009, Igor Kanshyn. All rights reserved.           *
 *                                                                   *
 *  JsCssMin is released under the Apache Software License.          *
 *  See LICENSE.txt for more details.                                *
 *                                                                   *
 *********************************************************************/

package org.grenader.jscssmin.files;

import java.io.*;

/**
 * <p>Product: JsCssMin ( JavaScript and CSS Minifier )<br>
 * Author: Igor Kanshyn (grenader).
 * </p>
 * Date: May 6, 2009
 */
class JsCssMinFileReader {
    protected File file;

    public JsCssMinFileReader(File file) {
        this.file = file;
    }

    String read() throws IOException {
        StringBuilder builder = new StringBuilder();
        InputStreamReader fileReader = null;
        BufferedReader reader = null;

        try {
            fileReader = getInputStream();
            reader = new BufferedReader(fileReader);

            String str = null;
            do {
                str = reader.readLine();
                if (str != null)
                    builder.append(str).append('\n');
            } while (str != null);
        } finally {
            if (reader != null)
                reader.close();
            if (fileReader != null)
                fileReader.close();
        }

        return builder.toString();
    }

    protected InputStreamReader getInputStream() throws FileNotFoundException, UnsupportedEncodingException {
        return new InputStreamReader(new FileInputStream(this.file));
    }

}
